package com.m.IO.Chars;

import java.io.*;

/**
 * 字符流
 * 自带缓冲区
 *
 * @author Mc.Chai
 * @program: Java基础
 * @create 2021-11-22-16:41 16:41
 */
public class TestReaderWriter {
    public static void main(String[] args) throws IOException {
        Writer writer=new FileWriter("chars.txt");
        writer.write("柴和程123abc");
        writer.flush();
        writer.close();
        Reader reader=new FileReader("chars.txt");
        char[] cache=new char[4];
        while (true){
            int n=reader.read(cache);   //reader.read(char[] a),将输入的内容存入数组，并返回所取到的个数
            if (n==-1)break;        //文件的尾部返回-1
            for (int i = 0; i < n; i++) {
                System.out.print(cache[i]);
            }
        }
    }
}
